﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Data.SqlClient;

/// <summary>
/// Summary description for DBController
/// </summary>
public class DBController
{
    private string connectionString;
    private static DBController instance;
    private SqlConnection sqlConn;
    DataClassesDataContext db;
    KostenPlaatsenDALController kpc;

	private DBController()
	{
        connectionString = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
        sqlConn = new SqlConnection(connectionString);
        db = new DataClassesDataContext();
        kpc = new KostenPlaatsenDALController(db);
	}

    public static DBController Instance
    {
        get
        {
            if (instance == null)
                instance = new DBController();
            return instance;
        }
    }

    public string ConnectionString
    {
        get
        {
            return connectionString;
        }
    }

    public string TestSQLConneciton()
    {
        string read = "";
        sqlConn.Open();
        SqlCommand cmd = new SqlCommand("select Kostenplaats from KostenPlaatsen", sqlConn);
        SqlDataReader rdr = cmd.ExecuteReader();

        while (rdr.Read())
        {
            read += rdr[0];
        }
        sqlConn.Close();
        return read;
    }

    public string TestLinqToSql()
    { 
        string read="";
        KostenPlaats kostpl= db.KostenPlaats.Single(kp => kp.idKostenplaats == 20);
        read = kostpl.Kostenplaats;


       // Kortingen korting=db.Kortingen.FirstOrDefault(kort => kort.actief ==true);
        return read;
    }

    public List<KostenPlaats> GetKostenPlaatsen()
    { 
        throw new NotImplementedException();
    }

    public KostenPlaatsenDALController KostenPlaatsenDALController
    {
        get
        {
            return kpc;
        }
    }

     
}